﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

//1.异常基类；
class BaseException
{
public:
	virtual void printError()
	{

	}
};
class NullPointerException :public BaseException
{
public:
	virtual void printError()
	{
		cout << "空指针异常！" << endl;
	}
};
class OutOfRangeException :public BaseException
{
public:
	virtual void printError()
	{
		cout << "越界异常！" << endl;
	}
};
void doWorkPolymorphism()
{
	//throw NullPointerException();
	throw OutOfRangeException();
}
void testExceptionPolymorphism()
{
	try
	{
		doWorkPolymorphism();
	}
	catch (BaseException& e)
	{
		e.printError();
	}
}

//main312：异常的多态使用
int main312()
{
	testExceptionPolymorphism();//空指针异常！ -->  越界异常！

	system("pause");
	return EXIT_SUCCESS;
}